import { defineStore } from 'pinia'
import router from '@/router'
import { localCache } from '@/utils/cache'
import { LOGIN_TOKEN } from '@/global/constants'

interface ILoginState {
  token: string
}
const useLoginStore = defineStore('login', {
  state: (): ILoginState => ({
    token: ''
  }),
  actions: {
    async loginUserAction(token: any) {
      // 账号登录，获取token等信息(由参数传值过来)
      this.token = token
      localCache.setCache(LOGIN_TOKEN, this.token)
      // 登录成功  跳转到main页面
      router.push('/main')
    }
  }
})

export default useLoginStore
